import request from '@/utils/useRequest'
export const httpUpload = (file) => {
    let formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
const getApi = (api) => {
    return  {
        list: (data) => {
            return request({
                url: `/${api}/list`,
                params: data,
                method: 'get'
            })
        },
            page: (data) => {
            return request({
                url: `/${api}`,
                params: data,
                method: 'get'
            })
        },
            read: (id) => {
            return request({
                url: `/${api}/` + id,
                method: 'get'
            })
        },
            update: (data) => {
            return request({
                url: `/${api}/` + data.id,
                data,
                method: 'put'
            })
        },
            create: (data) => {
            return request({
                url: `/${api}`,
                data,
                method: 'post'
            })
        },
            del: (id) => {
            return request({
                url: `/${api}/` + id,
                method: 'delete'
            })
        },
    }
}
export const http = {
    login: (data) => {
        return request({
            url: '/admin/login',
            data,
            method: 'post'
        })
    },
    policy: getApi('policy'),
    role: {
        ...getApi('role')
    },
    user: {
        ...getApi('user')
    },
    Coupon: {
        ...getApi('coupon')
    },
    CouponMember: {
        ...getApi('couponMember')
    },
    Banner: {
        list: (data) => {
            return request({
                url: '/banner/list',
                params: data,
                method: 'get'
            })
        },
        page: (data) => {
            return request({
                url: '/banner',
                params: data,
                method: 'get'
            })
        },
        read: (id) => {
            return request({
                url: '/banner/' + id,
                method: 'get'
            })
        },
        update: (data) => {
            return request({
                url: '/banner/' + data.id,
                data,
                method: 'put'
            })
        },
        create: (data) => {
            return request({
                url: '/banner',
                data,
                method: 'post'
            })
        },
        del: (id) => {
            return request({
                url: '/banner/' + id,
                method: 'delete'
            })
        },
    },
    Category: {
        list: (data) => {
            return request({
                url: '/category/list',
                params: data,
                method: 'get'
            })
        },
        page: (data) => {
            return request({
                url: '/category',
                params: data,
                method: 'get'
            })
        },
        read: (id) => {
            return request({
                url: '/category/' + id,
                method: 'get'
            })
        },
        update: (data) => {
            return request({
                url: '/category/' + data.id,
                data,
                method: 'put'
            })
        },
        create: (data) => {
            return request({
                url: '/category',
                data,
                method: 'post'
            })
        },
        del: (id) => {
            return request({
                url: '/category/' + id,
                method: 'delete'
            })
        },
    },
    ProductList: {
        ...getApi('project')
    },
    ProductOrder: {
        ...getApi('order'),
        refund: (data) => {
            return request({
                url: '/order/refund',
                data,
                method: 'post'
            })
        }
    },
    ProductOrderDetail: {
        ...getApi('orderDetail')
    },
    Member: {
        ...getApi('member')
    },
    MemberAddress: {
        ...getApi('address'),
        updateStatus: (data) => {
            return request({
                url: '/address/updateStatus',
                data,
                method: 'post'
            })
        }
    },
    Consult: {
        ...getApi('consult')
    },
    Comment: {
        ...getApi('comment')
    },
    Staff: {
        ...getApi('staff')
    },
    city: {
        ...getApi('city')
    },
    travelMode: {
        ...getApi('travelMode')
    },
    staffApply: {
        ...getApi('staffApply')
    },
    staffBalance: {
        ...getApi('staffBalance'),
        audit: (data) => {
            return request({
                url: '/staffBalance/audit',
                data,
                method: 'post'
            })
        }
    }
}
